/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package windowgravitydemo;

import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JPanel;

/**
 *
 * @author PHU QUOC
 */
public class MainPanel extends JPanel implements Runnable{
    private int stringposx;
    private Thread mainthread;    
    private boolean isrunning = true;
    public MainPanel(){
        isrunning = true;
        mainthread = new Thread(this);
        setSize(200, 200);
        stringposx = getWidth();
    }
    public void initialize(){
        mainthread.start();
    }
    @Override
    public void paint(Graphics g){
        g.setColor(Color.LIGHT_GRAY);
        g.fillRect(0, 0, getWidth(), getHeight());
        g.setColor(Color.BLACK);
        g.drawString("Mr.D.MGD", stringposx, 100);
    }
    public void run(){
         while(isrunning){
            try{
                Thread.sleep(10);
            }
            catch(Exception e){}
            stringposx --;
            if(stringposx < -55)
                stringposx = getWidth();
            repaint();
        }
    }
}
